<template>
	<view>
		<!-- 地址列表 -->
		<view class="u-p-t-20 u-p-b-20" v-if="act == false">
			<u-cell-group>
				<u-cell-item :arrow="false" class="item" v-for="(res, index) in siteList" :key="res.id" @click="chooseAddress(res)">
					
					<view class="u-flex" :class="res.isaccept?'':'none'">
						<view class="" style="margin-right: 30rpx;" v-if="res.id == acaddress ">
							<u-icon color="rgb(16, 190, 202)" size="38"   name="checkmark-circle"></u-icon>
						</view>
						<view class="" style="margin-right: 30rpx;" v-if="res.id !== acaddress ">
							<view class="yuan">
								
							</view>
						</view>
						<view class="u-flex-1">
							<view class="" style="display: flex; justify-content: space-between;">
								<view class="top">
									<view class="name">{{ res.name }}</view>
									<view class="">
										<view class="phone">{{ res.mobile }}</view>
									</view>
									<view class="tag" v-if="res.isdefault">
										<text class="bg-gradual-blue">默认</text>
									</view>
								</view>
								<view class="" @tap.stop="openEdit(res)" >
									<u-icon name="edit-pen" size="48"></u-icon>
								</view>
							</view>
							<view class="bottom u-line-1">
								{{res.address}}
							</view>
						</view>
					</view>
				</u-cell-item>
			</u-cell-group>
		</view>
		<!-- 添加或修改地址 -->
		<view class="u-p-t-20 u-p-b-20" v-if="act == true">
			<address-add :addressId="addressId" :type="type" @edit="edit" @add="add" @back="back"></address-add>
		</view>
		<!-- <view class="addSite bg-gradual-blue" @tap="openAdd" v-if="isLogin && act == false"> -->
		<view class="addSite bg-gradual-blue" @tap="openAdd" v-if="act == false">
			<view class="add">
				<u-icon name="plus" color="#ffffff" class="icon" :size="30"></u-icon><text>新建收货地址</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			siteList: {},
			acaddress:"",
		},
		data() {
			return {
				addressId: 0,
				type: 'add',
				act: false
			};
		},
		created() {
			// this.getData();
		},
		methods: {
			openEdit(res) {
				// 修改地址
				console.log(res)
				// let edit = 'edit'
				// uni.navigateTo({
				// 	url: `/pages/my/addressSet/addSite/addSite?id=${res.id}&edit=${edit}`
				// })
				this.addressId = res.id
				this.type = "edit"
				this.act = true
			},
			openAdd(){
				this.addressId = 0
				this.type = "add"
				this.act = true
			},
			add(){
				this.act = false
				this.$emit('update')
			},
			edit(){
				this.act = false
				this.$emit('update')
			},
			back(){
				this.act = false
			},
			chooseAddress(item) {
				if (!item.isaccept) {
					uni.showToast({
						title: '当前地址不在服务范围内，请选择其他地址',
						icon: 'none'
					})
					return
				}
				this.$emit('chooseAddress', item)
			},
			// toAddSite() {
			// 	uni.navigateTo({
			// 		url: '/pages/my/addressSet/addSite/addSite?type=add'
			// 	});
			// }
		}
	};
</script>

<style lang="scss" scoped>
	.item {
		// padding: 40rpx 20rpx;
		background-color: #ffffff;
		width: 100%;

		// border-bottom: 1px solid $u-border-color;
		.none {
			opacity: 0.4;
		}

		.top {
			display: flex;
			font-weight: bold;
			font-size: 32rpx;
			color: #000;

			.phone {
				margin-left: 50rpx;
			}

			.tag {
				display: flex;
				font-weight: normal;
				align-items: center;

				text {
					display: block;
					width: 60rpx;
					height: 34rpx;
					line-height: 34rpx;
					color: #ffffff;
					font-size: 20rpx;
					border-radius: 6rpx;
					text-align: center;
					margin-left: 30rpx;
					background-color: rgb(49, 145, 253);
				}

				.red {
					background-color: red
				}
			}
		}

		.bottom {
			// display: flex;
			// margin-top: 20rpx;
			font-size: 28rpx;
			// justify-content: space-between;
			color: #999999;
			width: 610rpx;
			text-align: left;
		}
	}

	.addSite {
		display: flex;
		justify-content: space-around;
		width: 600rpx;
		line-height: 100rpx;
		position: absolute;
		bottom: 30rpx;
		left: 80rpx;
		background-color: red;
		border-radius: 60rpx;
		font-size: 30rpx;

		.add {
			display: flex;
			align-items: center;
			color: #ffffff;

			.icon {
				margin-right: 10rpx;
			}
		}
	}
	.yuan{
		width: 36rpx;
		height: 36rpx;
		background-color: white;
		border: 4rpx solid rgb(16, 190, 202);
		border-radius: 20rpx;
	}
</style>
